package org.wmq.travelagency02.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.wmq.travelagency02.constant.OrderStatusConstant;
import org.wmq.travelagency02.mapper.OrderMapper;
import org.wmq.travelagency02.model.Entity.Order;
import org.wmq.travelagency02.service.OrderService;

@Service
@RequiredArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Override
    public Order getByTravellerIdAndTourGroupId(Long travellerId, Long tourGroupId) {
        Order result = this.lambdaQuery().eq(Order::getTravellerId, travellerId)
                .eq(Order::getTourGroupId, tourGroupId)
                .select(
                        Order::getAmount,
                        Order::getStatus,
                        Order::getPaymentMethod
                ).one();
        if (result == null){
            return null;
        }
        result.setTravellerId(travellerId);
        result.setTourGroupId(tourGroupId);
        return result;
    }

    @Override
    public void removeByTravellerIdAndTourGroupId(Long travellerId, Long tourGroupId) {
        this.lambdaUpdate().eq(Order::getTravellerId, travellerId)
                .eq(Order::getTourGroupId, tourGroupId).clear();
    }

    @Override
    @Transactional
    public boolean updateStatusById(Long id, Integer status) {
        //TODO: 2022/4/16 订单状态更新
        return true;
    }
}
